<?php
/**
 * Created by PhpStorm.
 * User: xuyiping
 * Date: 2018/7/5
 * Time: 11:26
 */
namespace app\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Admin\GoldController;
use App\Model\GoldRecordModel;
use App\Http\Controllers\Api\ApiMainController;
use App\Model\WebUserModel;
class ApiGoldRecordController  extends ApiMainController
{
    //*金豆明细//*/
    public function index(Request $request)
    {
        if ($this->_defalutJson['code'] == -1 && empty($this->userId)) {
            return response()->json(array(
                'code' => 404,
                'message' => $this->_defalutJson['message'],
            ));
        }
        $limit = $request->input('limit') ? intval($request->input('limit')) : 10;//默认显示10
        $groups = GoldRecordModel::where(array("iUserID" => $this->userId))
            ->orderBy('dtModifyTime', "DESC")
            ->paginate($limit)
            ->toArray();
        foreach($groups['data'] as &$value){

            if($value['iConsumeType']==1 || $value['iConsumeType']==2){
                $tem = json_decode($value['sRemark'],true);
                $value['score']=$tem['score'];
                $user_data1 = WebUserModel::where('iSeqId',$tem['user1'])->first();
                $user_data2 = WebUserModel::where('iSeqId',$tem['user2'])->first();

                $value['user1']=empty($user_data1) ? '': urldecode($user_data1->sUserName);
                $value['user2']=empty($user_data2) ? '': urldecode($user_data2->sUserName);
            }
        }
        //返回数组

        return response()->json(array(
            'code' => 200,
            'message' => "查询成功",
            "date" => array(
                "uuid" => $this->uuid,
                "total" => $groups['total'],
                "current_page" => $groups['current_page'],
                "list" => $groups['data'],
            )
        ));
    }
}

